<!--
 * @Description: 一卡通购买记录
 * @Author: Li Yujie
 * @Date: 2021/1/29
 * @Last Modified by: Li Yujie
 * @Last Modified time: 2021/1/29
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    购买记录
                </div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        用户信息
                    </p>
                    <el-input
                        placeholder="注册手机号、用户昵称或用户编号"
                        v-model="filterData.user_keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 300px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        上级精英
                    </p>
                    <el-input
                        placeholder="注册手机号、用户昵称或用户编号"
                        v-model="filterData.agent_keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 300px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        下单时间
                    </p>
                    <el-date-picker
                        v-model="dateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 400px"
                        value-format="timestamp"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->

            <div style="margin-bottom: 18px">
                售卡数量统计：{{ stat.buy_count }} 购卡用户数统计：{{ stat.user_count }}
            </div>
            <!-- table -->
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%;"
                ref="tempLateName"
                class="data-table"
                v-loading="tableLoading"
            >
                <el-table-column
                    label="序号"
                    align="center"
                    width="80"
                    type="index"
                />
                <el-table-column
                    label="用户信息"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div class="table-item">用户昵称：{{ scope.row.true_name }}</div>
                        <div class="table-item">手机号：{{ scope.row.phone }}</div>
                        <div class="table-item">用户编号：{{ scope.row.student_no }}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="上级精英"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div class="table-item">用户昵称：{{ scope.row.parent_true_name ? scope.row.parent_true_name : '--' }}</div>
                        <div class="table-item">手机号：{{ scope.row.parent_phone ? scope.row.parent_phone : '--' }}</div>
                        <div class="table-item">邀请码：{{ scope.row.parent_invite_code ? scope.row.parent_invite_code : '--' }}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="使用有效期"
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div>{{ scope.row.buy_start_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }} -</div>
                        <div>{{ scope.row.buy_end_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="下单时间"
                    align="center"
                    width="200"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.buy_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="实付款"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div>￥{{ scope.row.pay_money }}</div>
                    </template>
                </el-table-column>
            </el-table>
            <!-- /table -->

            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'BuyRecords',
    mixins: [back],
    components: {},
    data() {
        return {
            filterData: {
                // 会员卡编号
                vip_no: '',
                // 用户信息
                user_keyword: '',
                // 上级精英
                agent_keyword: '',
                // 下单时间
                start_time: '',
                end_time: ''
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            stat: {
                buy_count: 0,
                user_count: 0
            },
            dateTimeRange: [],
        };
    },
    computed: {},
    watch: {
        dateTimeRange(value) {
            this.filterData.start_time = value ? value[0] / 1000 : '';
            this.filterData.end_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        }
    },

    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '商城'}, {title: '一卡通管理', path: '/student/member-card-list'},{title: '购买记录'}]);
        this.filterData.vip_no = this.$route.query.vip_no;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {

            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/student_vip%5Cget_buy_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                    this.stat = res.data.stat;
                }
                this.tableLoading = false;
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        padding: 24px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin-left: 12px;
                margin-bottom: 24px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            margin-top: 24px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 24px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }

            .input-with-select {
                width: 300px;
                margin-right: 32px;
            }

            /deep/ .input-with-select .el-input-group__prepend {
                background-color: #fff;
                width: 130px;
            }
        }

        /* 分页 */

        .pagination-wrapper {
            padding-top: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    .table-item {
        margin: 6px 0;
    }

    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
}
</style>

